//
//  DXHomeRetweetView.swift
//  新浪微博
//
//  Created by dix on 2017/2/7.
//  Copyright © 2017年 dix. All rights reserved.
//

import UIKit

class DXHomeRetweetView: UIView {
    // 记录转发微博的底部约束
    var retweetViewBottomConstraint: Constraint?
    //提供属性高属性共外界赋值
    var statusViewModel: DXStatusViewModel? {
        didSet{
            //赋值
            contentLabel.text = statusViewModel?.homeModel?.retweeted_status?.text
            //先卸载约束
            retweetViewBottomConstraint?.uninstall()
            //判断是否有配图
            if let picUrls = statusViewModel?.homeModel?.retweeted_status?.pic_urls, picUrls.count > 0 {
                //赋值
                pictureView.pic_urls = picUrls
                //设置约束
                self.snp_makeConstraints(closure: { (make) in
                   retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
                })
                //显示配图
                pictureView.isHidden = false
            }else {
                
                self.snp_makeConstraints(closure: { (make) in
                   retweetViewBottomConstraint = make.bottom.equalTo(contentLabel).offset(10).constraint
                })
                //影藏配图
                pictureView.isHidden = true
            }
        
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        setUpUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //MARK: - 设置视图
    private func setUpUI(){
        backgroundColor = RGB(r: 235, g: 235, b: 235)
        //添加控件
        addSubview(contentLabel)
        addSubview(pictureView)
        //添加约束
        contentLabel.snp_makeConstraints { (make) in
            make.top.left.equalTo(10)
            make.width.equalTo(DXSCREENW - 20)
        }
        pictureView.snp_makeConstraints { (make) in
            make.left.equalTo(10)
            make.top.equalTo(contentLabel.snp_bottom).offset(10)
//            make.size.equalTo(CGSize(width: 100, height: 100))
        }
        snp_makeConstraints { (make) in
           retweetViewBottomConstraint = make.bottom.equalTo(pictureView).offset(10).constraint
        }
        
    
    }
    //MARK: - 懒加载控件
    private lazy var contentLabel: UILabel = {
        let lab = UILabel(fontSize: DXNORMALFONTSIZE, textColor: UIColor.darkGray)
        //换行
        lab.numberOfLines = 0
        return lab
    
    }()
    private lazy var pictureView:DXHomePictureView = {
        let view = DXHomePictureView()
        view.backgroundColor = self.backgroundColor
        return view
    }()
    
}
